(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:TemplatemsgCtrl
     * @description
     * # TemplatemsgCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('TemplatemsgCtrl', TemplatemsgCtrl);

    TemplatemsgCtrl.$inject = ['$scope', 'dataService', 'helper', '$rootScope', '$location'];

    function TemplatemsgCtrl($scope, dataService, helper, $rootScope, $location) {
        $scope.listAction = function() {
            $scope.pageSize = 10;
            $scope.getList(1);
        }

        $scope.getList = function(pageNo) {
            var query = {
                pageNo: pageNo ? pageNo : "1",
                pageSize: $scope.pageSize
            };
            return dataService.templateList(query).then(function(data) {
                if (data.template_list) {
                    $scope.template_list = data.template_list;
                    $scope.total_count = data.total_count;
                }
            });
        }

        //选中模板标题 关键词
        $scope.titleCheck = function(title) {
            dataService.templateLibrarySave(title).then(function(result) {
                if (result.Msg == "ok") {
                    helper.myAlert("success", "#/templatemsg/list");
                } else {
                    helper.myAlert("error：" + result.Msg);
                    return false;
                }
            });
        }
    }
})();